Break Diagram into it's own controller, nest resources

Conflicts:
app/views/scenarios/show.html.erb

Alex Coomans 10 years ago
parent
commit
15e3f0a33d

+ 0 - 8
app/controllers/agents_controller.rb

@@ -98,14 +98,6 @@ class AgentsController < ApplicationController
98 98
     @agent = current_user.agents.find(params[:id])
99 99
   end
100 100
 
101
-  def diagram
102
-    @agents = if params[:scenario_id].present?
103
-                current_user.scenarios.find(params[:scenario_id]).agents.includes(:receivers)
104
-              else
105
-                current_user.agents.includes(:receivers)
106
-              end
107
-  end
108
-
109 101
   def create
110 102
     @agent = Agent.build_for_type(params[:agent].delete(:type),
111 103
                                   current_user,

+ 9 - 0
app/controllers/diagrams_controller.rb

@@ -0,0 +1,9 @@
1
+class DiagramsController < ApplicationController
2
+  def show
3
+    @agents = if params[:scenario_id].present?
4
+                current_user.scenarios.find(params[:scenario_id]).agents.includes(:receivers)
5
+              else
6
+                current_user.agents.includes(:receivers)
7
+              end
8
+  end
9
+end

+ 2 - 2
app/controllers/events_controller.rb

@@ -2,8 +2,8 @@ class EventsController < ApplicationController
2 2
   before_filter :load_event, :except => :index
3 3
 
4 4
   def index
5
-    if params[:agent]
6
-      @agent = current_user.agents.find(params[:agent])
5
+    if params[:agent_id]
6
+      @agent = current_user.agents.find(params[:agent_id])
7 7
       @events = @agent.events.page(params[:page])
8 8
     else
9 9
       @events = current_user.events.preload(:agent).page(params[:page])

+ 1 - 1
app/views/agents/_table.html.erb

@@ -53,7 +53,7 @@
53 53
         </td>
54 54
         <td class='<%= "agent-disabled" if agent.disabled? %>'>
55 55
           <% if agent.can_create_events? %>
56
-            <%= link_to(agent.events_count || 0, events_path(:agent => agent.to_param)) %>
56
+            <%= link_to(agent.events_count || 0, agent_events_path(agent)) %>
57 57
           <% else %>
58 58
             <span class='not-applicable'></span>
59 59
           <% end %>

+ 1 - 2
app/views/agents/index.html.erb

@@ -12,9 +12,8 @@
12 12
       <div class="btn-group">
13 13
         <%= link_to '<span class="glyphicon glyphicon-plus"></span> New Agent'.html_safe, new_agent_path, class: "btn btn-default" %>
14 14
         <%= link_to '<span class="glyphicon glyphicon-refresh"></span> Run event propagation'.html_safe, propagate_agents_path, method: 'post', class: "btn btn-default" %>
15
-        <%= link_to '<span class="glyphicon glyphicon-random"></span> View diagram'.html_safe, diagram_agents_path, class: "btn btn-default" %>
15
+        <%= link_to '<span class="glyphicon glyphicon-random"></span> View diagram'.html_safe, diagram_path, class: "btn btn-default" %>
16 16
       </div>
17 17
     </div>
18 18
   </div>
19 19
 </div>
20
-

+ 2 - 2
app/views/agents/show.html.erb

@@ -15,7 +15,7 @@
15 15
           <li><a href="#logs" data-toggle="tab" data-agent-id="<%= @agent.id %>" class='<%= @agent.recent_error_logs? ? 'recent-errors' : '' %>'><span class='glyphicon glyphicon-list-alt'></span> Logs</a></li>
16 16
 
17 17
           <% if @agent.can_create_events? && @agent.events.count > 0 %>
18
-            <li><%= link_to '<span class="glyphicon glyphicon-random"></span> Events'.html_safe, events_path(:agent => @agent.to_param) %></li>
18
+            <li><%= link_to '<span class="glyphicon glyphicon-random"></span> Events'.html_safe, agent_events_path(@agent) %></li>
19 19
           <% else %>
20 20
             <li class='disabled'><a><span class='glyphicon glyphicon-random'></span> Events</a></li>
21 21
           <% end %>
@@ -103,7 +103,7 @@
103 103
             <% if @agent.can_create_events? %>
104 104
               <p>
105 105
                 <b>Events created:</b>
106
-                <%= link_to @agent.events.count, events_path(:agent => @agent.to_param) %>
106
+                <%= link_to @agent.events.count, agent_events_path(@agent) %>
107 107
               </p>
108 108
             <% end %>
109 109
 

app/views/agents/diagram.html.erb → app/views/diagrams/show.html.erb


+ 1 - 1
app/views/layouts/application.html.erb

@@ -41,7 +41,7 @@
41 41
         agentPaths["New Agent"] = <%= Utils.jsonify new_agent_path %>;
42 42
         agentPaths["Account"] = <%= Utils.jsonify edit_user_registration_path %>;
43 43
         agentPaths["Events Index"] = <%= Utils.jsonify events_path %>;
44
-        agentPaths["View Agent Diagram"] = <%= Utils.jsonify diagram_agents_path %>;
44
+        agentPaths["View Agent Diagram"] = <%= Utils.jsonify diagram_path %>;
45 45
         agentPaths["Run Event Propagation"] = { url: <%= Utils.jsonify propagate_agents_path %>, method: 'POST' };
46 46
 
47 47
 

+ 1 - 1
app/views/scenarios/show.html.erb

@@ -15,7 +15,7 @@
15 15
 
16 16
       <div class="btn-group">
17 17
         <%= link_to '<span class="glyphicon glyphicon-chevron-left"></span> Back'.html_safe, scenarios_path, class: "btn btn-default" %>
18
-        <%= link_to '<span class="glyphicon glyphicon-random"></span> View Diagram'.html_safe, diagram_agents_path(:scenario_id => @scenario.to_param), class: "btn btn-default" %>
18
+        <%= link_to '<span class="glyphicon glyphicon-random"></span> View Diagram'.html_safe, scenario_diagram_path(@scenario), class: "btn btn-default" %>
19 19
         <%= link_to '<span class="glyphicon glyphicon-edit"></span> Edit'.html_safe, edit_scenario_path(@scenario), class: "btn btn-default" %>
20 20
         <% if @scenario.source_url.present? %>
21 21
           <%= link_to '<span class="glyphicon glyphicon-plus"></span> Update'.html_safe, new_scenario_imports_path(:url => @scenario.source_url), class: "btn btn-default" %>

+ 6 - 1
config/routes.rb

@@ -11,7 +11,6 @@ Huginn::Application.routes.draw do
11 11
       post :propagate
12 12
       get :type_details
13 13
       get :event_descriptions
14
-      get :diagram
15 14
     end
16 15
 
17 16
     resources :logs, :only => [:index] do
@@ -19,8 +18,12 @@ Huginn::Application.routes.draw do
19 18
         delete :clear
20 19
       end
21 20
     end
21
+
22
+    resources :events, :only => [:index]
22 23
   end
23 24
 
25
+  resource :diagram, :only => [:show]
26
+
24 27
   resources :events, :only => [:index, :show, :destroy] do
25 28
     member do
26 29
       post :reemit
@@ -36,6 +39,8 @@ Huginn::Application.routes.draw do
36 39
       get :share
37 40
       get :export
38 41
     end
42
+
43
+    resource :diagram, :only => [:show]
39 44
   end
40 45
 
41 46
   resources :user_credentials, :except => :show

+ 2 - 2
spec/controllers/events_controller_spec.rb

@@ -15,12 +15,12 @@ describe EventsController do
15 15
 
16 16
     it "can filter by Agent" do
17 17
       sign_in users(:bob)
18
-      get :index, :agent => agents(:bob_website_agent)
18
+      get :index, :agent_id => agents(:bob_website_agent)
19 19
       assigns(:events).length.should == agents(:bob_website_agent).events.length
20 20
       assigns(:events).all? {|i| i.agent.should == agents(:bob_website_agent) }.should be_true
21 21
 
22 22
       lambda {
23
-        get :index, :agent => agents(:jane_website_agent)
23
+        get :index, :agent_id => agents(:jane_website_agent)
24 24
       }.should raise_error(ActiveRecord::RecordNotFound)
25 25
     end
26 26
   end